@tool
class_name AdditionalEffect_Action_AddAnimKeyEvent
extends AdditionalEffect_Action

#region 属性
@export var anim_name:String
@export var time:float
@export var method_name:String
@export var method_args:Dictionary[String,Variant]
@export var bind_obj_path:NodePath
@export var no_method_name_additional_effects:Array[AdditionalEffect]
var add_call_method_track_res:AddCallMethodTrackRes
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
## 初始化
func init(args:Dictionary = {}):
	if super(args):
		for additional_effect in no_method_name_additional_effects:
			self.args["Target"] = target
			self.args["Owner"] = self
			self.args["Action"] = action
			additional_effect.init(args)
		return true
	return false
## 检查能否执行添加效果，默认为true
func can_excute() -> bool:
	var bind_node = action.get_node(bind_obj_path) if bind_obj_path else action
	return super() and is_instance_valid(bind_node) and (method_name.is_empty() or (not method_name.is_empty() and bind_node.has_method(method_name)))
## 执行添加效果
func excute() -> bool:
	if super():
		target = target as Entity
		var animation_component:AnimationComponent = target.get_component(AnimationComponent)
		if animation_component and anim_name:
			if method_name:
				var bind_node = action.get_node(bind_obj_path)
				add_call_method_track_res = animation_component.add_call_method_track_and_method(anim_name,time,method_name,args.values(),bind_node)
			else:
				var bind_node = action
				var args_temp = method_args.duplicate(true)
				args_temp.set("AdditionalEffects",no_method_name_additional_effects)
				add_call_method_track_res = animation_component.add_call_method_track_and_method(anim_name,time,"_on_anim_key_event",[args_temp],bind_node)
		return true
	else:
		return false
## 取消执行的效果
func cancel_excute() -> bool:
	if super():
		if add_call_method_track_res:
			add_call_method_track_res.destroy.call()
		return true
	else:
		return false
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
#endregion
